package io.renren.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.SubVesselEntity;
import io.renren.service.SubVesselService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;


/**
 * 船舶主数据表
 * 
 * @author
 * @email
 * @date 2017-06-28 17:40:40
 */
@RestController
@RequestMapping("subvessel")
public class SubVesselController {
	@Autowired
	private SubVesselService subVesselService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("subvessel:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SubVesselEntity> subVesselList = subVesselService.queryList(query);
		int total = subVesselService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(subVesselList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{createTime}")
	@RequiresPermissions("subvessel:info")
	public R info(@PathVariable("createTime") Date createTime){
		SubVesselEntity subVessel = subVesselService.queryObject(createTime);
		
		return R.ok().put("subVessel", subVessel);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("subvessel:save")
	public R save(@RequestBody SubVesselEntity subVessel){
		subVesselService.save(subVessel);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("subvessel:update")
	public R update(@RequestBody SubVesselEntity subVessel){
		subVesselService.update(subVessel);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("subvessel:delete")
	public R delete(@RequestBody Date[] createTimes){
		subVesselService.deleteBatch(createTimes);
		
		return R.ok();
	}
	
}
